package com.googlecode.spruce.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "service_group_schedule")
public class ServiceGroupSchedule implements Serializable
{
    /** Serial ID */
    private static final long serialVersionUID = -3318253622178228270L;

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column(name = "cron")
    private String cron;

    @ManyToOne
    @JoinColumn(name = "host_id")
    private Host host;

    @ManyToOne
    @JoinColumn(name = "service_group_id")
    private ServiceGroup serviceGroup;

    /**
     * @return the cron
     */
    public String getCron()
    {
        return cron;
    }

    /**
     * @param cron
     *            the cron to set
     */
    public void setCron(final String cron)
    {
        this.cron = cron;
    }

    public Integer getId()
    {
        return id;
    }

    public void setId(final Integer id)
    {
        this.id = id;
    }

    /**
     * @return the host
     */
    public Host getHost()
    {
        return host;
    }

    /**
     * @param host
     *            the host to set
     */
    public void setHost(final Host host)
    {
        this.host = host;
    }

    /**
     * @return the serviceGroup
     */
    public ServiceGroup getServiceGroup()
    {
        return serviceGroup;
    }

    /**
     * @param serviceGroup
     *            the serviceGroup to set
     */
    public void setServiceGroup(final ServiceGroup serviceGroup)
    {
        this.serviceGroup = serviceGroup;
    }

    /**
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((host == null) ? 0 : host.hashCode());
        result = prime * result + ((serviceGroup == null) ? 0 : serviceGroup.hashCode());
        return result;
    }

    /**
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(final Object obj)
    {
        if (this == obj)
        {
            return true;
        }
        if (obj == null)
        {
            return false;
        }
        if (getClass() != obj.getClass())
        {
            return false;
        }
        ServiceGroupSchedule other = (ServiceGroupSchedule) obj;
        if (host == null)
        {
            if (other.host != null)
            {
                return false;
            }
        }
        else if (!host.equals(other.host))
        {
            return false;
        }
        if (serviceGroup == null)
        {
            if (other.serviceGroup != null)
            {
                return false;
            }
        }
        else if (!serviceGroup.equals(other.serviceGroup))
        {
            return false;
        }
        return true;
    }
}
